package org.atovio.blog.controller;

import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;
import org.atovio.blog.model.pojo.People;
import org.atovio.blog.model.vo.PeopleVO;
import org.atovio.blog.service.PeopleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @author AtoVio, Winter Yuan
 */
@Controller
@RequiredArgsConstructor
public class PeopleController {

    private final PeopleService peopleService;

    @GetMapping({"/", "/people/hot"})
    public String showHotPeople(Model model) {
        List<People> peoplePOList = peopleService.queryTopPeople();

        // 转为VO？使用hutool工具类
        List<PeopleVO> peopleVOList = BeanUtil.copyToList(peoplePOList, PeopleVO.class);

        // 添加到model中
        model.addAttribute("peopleList", peopleVOList);

        // 视图
        return "/blog/peopleList";
    }
}
